/**
 *
 * @Description TODO
 * @Author liuer
 * @CreateTime 2024年05月07日 09:59
 */
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:yt_devops/pages/site/widgets/power_rank_tab.dart';
import 'package:yt_devops/utils/enums.dart';
import 'package:dart_date/dart_date.dart';
import '../resources/str_res_keys.dart';

///格式化工具类
class FormatUtil {
  ///逗号分割数值
  static String commaSeparatedDigits(dynamic number, {String? locale}) {
    return NumberFormat.decimalPattern(locale).format(number);
  }

  static String getToolTipFormater(
      {required StatisticUnitStatusType timeType,
      required int chartType,
      required PowerRankTabType selectedType,
      required DateTime time}) {
    return '''
     function (params) {
      var timeArr = params[0].name.split(':');
      const currentDateTime = new Date(2023, 1, 1, timeArr[0], timeArr[1], 0, 0);
      const dateTime = $chartType == 0 
        ? currentDateTime
        : currentDateTime.setHours(currentDateTime.getHours() + 1);
      const time = currentDateTime.toTimeString().substring(0, 5);
      var date = ${timeType == StatisticUnitStatusType.day || timeType == StatisticUnitStatusType.accumulate} 
      ? params[0].name 
      : ${timeType == StatisticUnitStatusType.month}
        ? '${time.getYear}-${time.getMonth > 9 ? time.getMonth : '0${time.getMonth}'}-' + params[0].name 
        : '${time.getYear}-' + params[0].name;
      let result =
          (${timeType == StatisticUnitStatusType.day && chartType != 0} ? `\${params[0].name}-\${time}` : date) + '<br />';
      params.forEach((item) => {
          let seriesName = item.seriesName;
          if (${selectedType == PowerRankTabType.profit}) {
            //收益
            seriesName += `(${ResKey.yuan.tr})`;
          } else {
            seriesName += ${timeType == StatisticUnitStatusType.day && chartType == 0} ? '(kW)' : '(kWh)' ;
          }
          var valueArr = item.value.toString();
          
          let label = `\${item.marker} \${seriesName}: \${valueArr}`;
          if (item.seriesName == '储能' || item.seriesName == 'Energy storage') {
            //储能系统
            if(item.value > 0){
            label += `(${ResKey.charge.tr})`
            }else  if(item.value < 0){
            label += `(${ResKey.discharge.tr})`
            }
            // if (item.value) item.value > 0 ? (label += `(${ResKey.charge.tr})`) : (label += `(${ResKey.discharge.tr})`);
          }
          result += `\${label}<br />`;
        });
        return result;
      },
    ''';
  }

  ///时间字符串转时间
  //String strDate = "12/31/2021";
  // DateTime date = DateFormat("MM/dd/yyyy").parse(strDate);
  // String strTime = "23:59:59";
  // DateTime time = DateFormat("HH:mm:ss").parse(strTime);
  // String strDate = "2021-12-31T23:59:59";
  // DateTime date = DateTime.parse(strDate);
  static DateTime timeStrToTime(String timeStr,{String format = 'yyyy-MM-dd'}) {
      return   DateFormat(format).parse(timeStr);
  }


}
